package gbench.appdemo.mall;

import java.io.IOException;

import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import gbench.appdemo.mall.erp.MyPlatform;

import java.util.*;
import java.util.function.Function;

/**
 * 以牡丹应用的模式(8082端口)进行启动 程序启动的使用请指定 jvm 参数选项为： -Dserver.port=8082
 * -Dserver.servlet.context-path=/mall
 * 
 * @author gbench
 *
 */
@ComponentScan(basePackages = {"gbench.appdemo.mall.appitf","gbench.appdemo.mall.mvc"})
@SpringBootApplication
public class BootstrapMall {

    /**
     * started callback
     * 
     * @return ApplicationRunner
     */
    @Bean
    ApplicationRunner onStarted() {
        return args -> {
            
        };
    }
    
    @Bean
    public Function<String, MyPlatform> platformGetter() {
        return name -> platforms.computeIfAbsent(name, e -> {
            return new MyPlatform();
        });
    }

    /**
     * 启动函数
     * 
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) {
        SpringApplication.run(BootstrapMall.class, args);
    }
    
    public Map<String,MyPlatform> platforms = new HashMap<String,MyPlatform>();
}
